package mb.model;  

import java.awt.Color;
import java.awt.Dimension;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JTextField;
import mb.config.Para;            // +

public class Box extends JPanel {

  // {+
  private Para para = Para.getPara();

  private static String boxTitle;

  {
    boxTitle = para.getT("boxTitle");
  }
  // +}

  public static final Color DEFAULT_COLOR = Color.ORANGE;
  public static final Color SELECTION_COLOR = Color.RED;
  public static final Color TITLE_COLOR = Color.WHITE;
  // public static final String TITLE_TEXT = "Box";  // -
  public static final Dimension BOX_SIZE = new Dimension(100, 50);

  private Color currentColor = Color.YELLOW;
  private boolean selected = false;
  private JTextField titleText = new JTextField(boxTitle);  // &

  public Box() {
    super();
    this.setSize(BOX_SIZE);
    this.setCurrentColor(DEFAULT_COLOR);

    titleText.setBackground(TITLE_COLOR);
    this.setLayout(new BorderLayout());
    this.add(titleText, "North");
    this.doLayout(); // no title shown without doLayout
  }

  public Color getCurrentColor(){
    return currentColor;
  }

  public void setCurrentColor(Color aColor) {
    if (aColor != SELECTION_COLOR) {
      currentColor = aColor;
      this.setBackground(aColor);
    }
    this.repaint();
  }

  public boolean isSelected(){
    return selected;
  }

  public void setSelected(boolean aSelected){
    selected = aSelected;
    if (selected) {
      this.setBackground(SELECTION_COLOR);
    }
    else {
      this.setBackground(currentColor);
    }
    this.repaint();
  }

}
